package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;
import cn.acewill.yxd.yunxundian.model.xingdongjihuaBean;

/**
 * Created by XXX on 2017/6/5.
 */

public class PlanInfoAdapter extends BaseAdapter{

    private Context context;
    private List<xingdongjihuaBean> list;
    private onPlanDeleteCallBack planDeleteCallBack;

    public PlanInfoAdapter(Context context,List<xingdongjihuaBean> list,onPlanDeleteCallBack planDeleteCallBack){
        this.context=context;
        this.list=list;
        this.planDeleteCallBack=planDeleteCallBack;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.taskplanlistview,parent,false);
            holder=new ViewHolder();
            holder.planTarget= (TextView) convertView.findViewById(R.id.planTarget);
            holder.planName= (TextView) convertView.findViewById(R.id.planName);
            holder.planTime= (TextView) convertView.findViewById(R.id.planTime);
            holder.principal= (TextView) convertView.findViewById(R.id.principal);
            holder.yardStick= (TextView) convertView.findViewById(R.id.yardStick);
            holder.deletePlan= (TextView) convertView.findViewById(R.id.deletePlan);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        xingdongjihuaBean bean=list.get(position);
        holder.planTarget.setText(bean.getMubiao());
        holder.planName.setText(bean.getTitle());
        String[] startTime=bean.getStime().split("-");
        String[] endTime=bean.getEtime().split("-");
        holder.planTime.setText(startTime[0]+"年"+startTime[1]+"月"+startTime[2]+"日"+"至"
                +endTime[0]+"年"+endTime[1]+"月"+endTime[2]+"日"+":"+bean.getPinglv());
        holder.principal.setText(bean.getCman());
        holder.yardStick.setText(bean.getHengliang());
        holder.deletePlan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                planDeleteCallBack.onplandelete(position);
            }
        });
        return convertView;

    }
    class ViewHolder{
        TextView planTarget;
        TextView planName;
        TextView planTime;
        TextView principal;
        TextView yardStick;
        TextView deletePlan;
    }

    public interface onPlanDeleteCallBack{
        void onplandelete(int position);
    }
}
